<template>
    <div class="app-container project-operate-container">
        <div>
            <el-row>
                <el-col :span="2">
                    <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" default-expand-all
                        highlight-current="true"></el-tree>
                </el-col>
                <el-col :span="22">
                    <div v-if="type == 1">
                        <ApprovalProject @change="close" :opt="edit" :id="pId" :index="indexSum" :is-close="false"></ApprovalProject>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div v-if="type == 2">
                        <ReviewProject @change="close" :opt="edit" :id="pId" :index="indexSum" :is-close="false"></ReviewProject>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div v-if="type == 3">
                        <ScheduleProject @change="close" :opt="edit" :id="pId" :sign="code" :index="indexSum"
                            :addShow="addShow">
                        </ScheduleProject>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div v-if="type == 4">
                        <DeliveryProject @change="close" :opt="edit" :id="pId" :index="indexSum" :sign="'主'">
                        </DeliveryProject>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div v-if="type == 5">
                        <Aftersales @change="close" :id="pId"></Aftersales>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div v-if="type == 6">
                        <EvaluateProject @change="close" :opt="edit" :id="pId" :sign="code" :index="indexSum">
                        </EvaluateProject>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div v-if="type == 7">
                        <Receivable @change="close" :id="pId"></Receivable>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                    <div v-if="type == 8">
                        <Costcontrol @change="close" :id="pId"></Costcontrol>
                        <div style="text-align: center;margin-top: 50px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>

import { listSales, getSales, updateClass, addSales, updateSales, getOrgName } from "@/api/project/sales";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import ReviewProject from '../review/operate.vue'
import ApprovalProject from './approval'
import ScheduleProject from './schedule'
import DeliveryProject from '../delivery/operate.vue'
import EvaluateProject from '../evaluation/evaluate.vue'
import { getScheduleName } from "@/api/project/projectSchedule";
import Receivable from './receivable'
import Costcontrol from './projectcost'
import Aftersales from './projectsales'
export default {
    dicts: ['project_status', 'certificate_type'],
    components: { ReviewProject, ScheduleProject, ApprovalProject, DeliveryProject, EvaluateProject, Receivable, Costcontrol, Aftersales },
    name: "ProjectInfo",
    props: {
        id: {
            type: String,
            default: ""
        },
        //序号
        index: {
            type: String,
            default: ""
        },
        opt: {
            type: String,
            default: ""
        },
        state: {
            type: String,
            default: ""
        },
        sign: {
            type: String,
            default: ""
        },
    },
    data() {
        return {
            typeCode: 'sales',
            type: 0,
            pId: "",
            code: "",
            indexSum: 0,
            edit: "",
            addShow: true,
            data: [],
            defaultProps: {
                children: 'children',
                label: 'label'
            },
            queryParams: {
                pageNum: 1,
                pageSize: 15,
                projectId: null,
                projectName: null,
                enterpriseName: null,
            },
            queryParamsSchedule: {
                projectId: null,
                state: null
            },
        };
    },
    created() {
        this.formaterData();
    },
    methods: {
        cancel() {
            this.$emit('change');
        },
        formaterData() {
            console.log(this.state)
            if (this.state == "0") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
                this.data = [{
                    label: '项目信息',
                    children: [{
                        label: '立项',
                    }]
                }]
            }
            if (this.state == "1") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
                this.data = [{
                    label: '项目信息',
                    children: [{
                        label: '立项',
                    }, {
                        label: '评审',
                    }]
                }]
            }
            if (this.state == "2") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
                this.data = [{
                    label: '项目信息',
                    children: [{
                        label: '立项',
                    }, {
                        label: '评审',
                    }, {
                        label: '进度',
                    }, {
                        label: '应收',
                    }, {
                        label: '成本',
                    }]
                }]
            }
            if (this.state == "3") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
                this.data = [{
                    label: '项目信息',
                    children: [{
                        label: '立项',
                    }, {
                        label: '评审',
                    }, {
                        label: '进度',
                    }, {
                        label: '交付',
                    }, {
                        label: '应收',
                    }, {
                        label: '成本',
                    }]
                }]
            }
            if (this.state == "4") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
                this.data = [{
                    label: '项目信息',
                    children: [{
                        label: '立项',
                    }, {
                        label: '评审',
                    }, {
                        label: '进度',
                    }, {
                        label: '交付',
                    }, {
                        label: '应收',
                    }, {
                        label: '成本',
                    }, {
                        label: '售后',
                    }]
                }]
            }
            if (this.state == "5") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
                this.data = [{
                    label: '项目信息',
                    children: [{
                        label: '立项',
                    }, {
                        label: '评审',
                    }, {
                        label: '进度',
                    }, {
                        label: '应收',
                    }, {
                        label: '成本',
                    }]
                }]
            }
            if (this.state == "6") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
                this.data = [{
                    label: '项目信息',
                    children: [{
                        label: '立项',
                    }, {
                        label: '评审',
                    }, {
                        label: '进度',
                    }, {
                        label: '交付',
                    }, {
                        label: '应收',
                    }, {
                        label: '成本',
                    }, {
                        label: '售后',
                    }, {
                        label: '评价',
                    }]
                }]
            }
        },
        handleNodeClick(data) {
            if (data.label == "立项") {
                this.indexSum = this.index;
                this.edit = "details"
                this.pId = this.id;
                this.type = 1
            }
            if (data.label == "评审") {
                this.indexSum = this.index;
                this.edit = "mainView"
                this.pId = this.id;
                this.type = 2
            }
            if (data.label == "进度") {
                this.edit = "details"
                this.indexSum = this.index
                this.pId = this.id;
                this.code = this.sign;
                //需要判断项目阶段是否全部完结
                this.queryParamsSchedule.projectId = this.id
                this.queryParamsSchedule.state = "0"//查询未完成的阶段
                getScheduleName(this.queryParamsSchedule).then(response1 => {
                    if (response1.data.length == 0) {
                        this.addShow = false
                    } else {
                        this.addShow = true
                    }
                })
                this.type = 3
            }
            if (data.label == "交付") {
                this.edit = "details"
                this.indexSum = this.index
                this.pId = this.id;
                this.code = this.sign;
                this.type = 4
            }
            if (data.label == "售后") {
                this.type = 5
            }
            if (data.label == "评价") {
                this.edit = "details"
                this.indexSum = this.index
                this.pId = this.id;
                this.code = this.sign;
                this.type = 6
            }
            if (data.label == "应收") {
                this.type = 7
            }
            if (data.label == "成本") {
                this.type = 8
            }
        },
        close() {
            this.type = 0;
        },
    }
};
</script>

<style scoped lang="scss">
.project-operate-container {
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px;
  max-width: 100%;
  max-height: 90vh;
  box-sizing: border-box;
}

// ... existing styles ...
</style>
